package com.fz.us.oa.core.service.common;

import com.fz.us.admin.base.bean.BaseEnumManager;
import com.fz.us.admin.base.bean.search.order.Order;
import com.fz.us.admin.base.bean.search.page.PagePaging;
import com.fz.us.admin.base.bean.search.result.SearchResultPaging;
import com.fz.us.admin.base.bean.search.rule.Rule;
import com.fz.us.admin.base.service.BaseService;

import com.fz.us.oa.core.entity.common.FileManage;
import com.mongodb.gridfs.GridFSDBFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * Service接口 - 附件
 * ============================================================================
 * 版权所有 2013 qshihua。
 * ----------------------------------------------------------------------------
 *
 * @author qshihua
 *
 * @version 0.1 2013-01-06
 */

public interface FileManagerService extends BaseService<FileManage, String> {

    /**
     * 从MongoDB中返回对应的文件
     * @param id    MongoDB中文件的主键：_id
     * @return
     */
    public GridFSDBFile gridFSGet(String id);

    /**
     * 分页
     *
     * @param page
     * @param order
     * @return
     */
    public SearchResultPaging pagingFile(PagePaging page, List<Rule> rules, Order order, BaseEnumManager.StateEnum... states);

    /**
     * 列表 Map
     *
     * @return {id:fileManage.id , name:fileManage.name}
     */
    public Map<String, Object> getListMap(FileManage fileManage);

    /**
     * 生成mongodb文件
     * @param inputStream
     * @param contentType
     * @param filename
     * @return
     * @throws IOException
     */
    public FileManage gridFSSave(InputStream inputStream, String contentType, String filename) throws IOException;

    /**
     * 生成mongodb文件并删除本地文件
     * @param file
     * @param contentType
     * @param filename
     * @return
     * @throws IOException
     */
    public FileManage gridFSSave(File file, String contentType, String filename) throws IOException;

    /**
     *
     * @param fileManage
     */
    public void gridFSDelete(FileManage fileManage);

    /**
     * 通过gridId查找FileManage
     */
    FileManage getFileManageByGridId(String gridId);


}